package com.qf.day10;
/**
 * 替换字符串的叠字
 * 例如，对于字符串 "hello nice to meet you"
 * 将其中出现两次的字符 ll 和 ee 分别替换为 l~ 和 e~
 * 输出为：hel~o nice to me~t you
 *"浩浩荡荡"
 * 输出为： 浩~荡~
 */
public class work2 {
    public static void main(String[] args) {
        String s = "hello nice to meet you";
        String s1 = "浩浩荡荡";
        String r = dealStr(s1);
        System.out.println(r);
    }

    public static String dealStr(String s) {
        char[] array = s.toCharArray();
        for (int i = 0; i < array.length-1; i++) {
            if(array[i] == array[i+1]){
                array[i+1] = '~';
            }
        }
        return  new String(array);
    }
}
